package com.hqyj.nacosdemo.provider.controller;

import com.hqyj.nacosdemo.provider.config.ServerConfig;
import com.hqyj.nacosdemo.provider.domain.Goods;
import com.hqyj.nacosdemo.provider.json.R;
import com.hqyj.nacosdemo.provider.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("goods")
public class GoodsController {

    @Resource
    private GoodsService goodsService;

    @Autowired
    private ServerConfig serverConfig;


    @GetMapping("/catalog/{catalogName}")
    public R queryGoodsListByCatalog(@PathVariable("catalogName") String catalogName) {
        List<Goods> goodsList = new ArrayList<Goods>();
        try {
            goodsList = goodsService.queryGoodsListByCatalog(catalogName);
            return R.success("查询商品资料成功！", goodsList,null, serverConfig.getIp());
        } catch (Exception ex) {
            ex.printStackTrace();
            return R.error("程序出现异常！");
        }
    }
}
